package com.leyou.item.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.leyou.item.dto.SpecGroupDTO;
import com.leyou.item.dto.SpecParamDTO;
import com.leyou.item.entity.SpecParam;
import com.leyou.item.mapper.SpecParamMapper;
import com.leyou.item.service.SpecParamService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 虎哥
 */
@Service
public class SpecParamServiceImpl extends ServiceImpl<SpecParamMapper, SpecParam> implements SpecParamService {


    @Override
    public List<SpecParamDTO> querySpecParams(Long ids, Object o, Object o1) {

        return SpecParamDTO.convertEntityList(query().eq("category_id", ids).list());
    }

    @Override
    public List<SpecParamDTO> queryparam(Long gid,Long cid) {
        List<SpecParam> groupId = query()
                .eq(null!=gid,"group_id", gid)
                .eq(null!=cid,"category_id", cid)
                .list();

        return SpecParamDTO.convertEntityList(groupId);
    }

    @Override
    public void addparam(SpecParamDTO specParamDTO) {
        SpecParam specParam = specParamDTO.toEntity(SpecParam.class);
        this.save(specParam);
    }

    @Override
    public void updateparam(SpecParamDTO specParamDTO) {
        SpecParam specParam = specParamDTO.toEntity(SpecParam.class);
        this.updateById(specParam);
    }
}